﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using Microsoft.Ted.Wacel.TestConsole.Properties;
using Microsoft.Ted.Wacel;
using System;

namespace Microsoft.Ted.Wacel.TestConsole
{
    public class TableStorageArrayTester
    {
        public static void ReadWriteArrayItem()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", 10, Settings.Default.StorageConnectionString);
            array[0] = 1234;
            VisualTester.AreEqual(1234, array[0]);
        }
        public static void WithoutRegion()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", int.MaxValue, Settings.Default.StorageConnectionString);
            array[int.MaxValue-1] = 1234;
            VisualTester.AreEqual(1234, array[int.MaxValue-1]);
        }
        public static void ReadWithoutWrite()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", int.MaxValue, Settings.Default.StorageConnectionString);
            int value = array[4567];
            VisualTester.AreEqual(0, value);
        }
        public static void IndexBoundary()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", 10, Settings.Default.StorageConnectionString);
            try
            {
                array[10] = 1234;
                VisualTester.Assert(false);
            }
            catch (IndexOutOfRangeException)
            {
                VisualTester.Assert(true);
            }
            catch (Exception exp)
            {
                VisualTester.Assert(false, exp.Message);
            }
        }
        public static void Length()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", 10, Settings.Default.StorageConnectionString);
            VisualTester.AreEqual(10, array.Length);
        }
        public static void OutofIndex()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", 10, Settings.Default.StorageConnectionString);
            try
            {
                array[11] = 1234;
                VisualTester.Assert(false);
            }
            catch (IndexOutOfRangeException)
            {
                VisualTester.Assert(true);
            }
            catch (Exception exp)
            {
                VisualTester.Assert(false, exp.Message);
            }
        }
        public static void LoopAccess()
        {
            TableStorage.Array<int> array = new TableStorage.Array<int>("myarray", 10, Settings.Default.StorageConnectionString);
            for (int i = 0; i < array.Length; i++)
                array[i] = i;
            for (int i = 0; i < array.Length; i++)
                array[i] += array[i];
            VisualTester.AreEqual(18, array[9]);
        }
    }
}
